set matsize 11000

* ) Insert directory
cd ""
use "Author-paper-referee level data", clear

**********************************
*Testing robustness of rank thresholds
drop IDEAS_1 IDEAS_2 IDEAS_3 IDEAS_5 referee_IDEAS_1 referee_IDEAS_2 referee_IDEAS_3 referee_IDEAS_5 
drop USNEWS_1 USNEWS_2 USNEWS_3 USNEWS_5 referee_USNEWS_1 referee_USNEWS_2 referee_USNEWS_3 referee_USNEWS_5

gen IDEAS_1 = (IDEASrank<=10)
gen referee_IDEAS_1 = (referee_IDEASrank<=10)
gen groupIDEASrankmatch = (IDEAS_1==1&referee_IDEAS_1==1) 

gen USNEWS_1 = (rank<=10)
gen referee_USNEWS_1 = (referee_rank<=10)
gen groupUSNEWSrankmatch = (USNEWS_1==1&referee_USNEWS_1==1) 

*****************************************
*Second PhD Match

global authorcontrols female gender_missing published_papers published_from_5_no_pp is_nber ///
	employmentrank1 employmentrank2 employmentrank3 employmentrank4 employmentrank5 NBER_AG-NBER_PE degree_1 degree_2

matrix b = (.,.,.,.)
	forvalues b = 5(1)50 {
	
	drop IDEAS_1 referee_IDEAS_1 groupIDEASrankmatch
	
	gen IDEAS_1 = (IDEASrank<=`b')
	gen referee_IDEAS_1 = (referee_IDEASrank<=`b')
	gen groupIDEASrankmatch = (IDEAS_1==1&referee_IDEAS_1==1) 

	display `b'
	qui reghdfe RR groupIDEASrankmatch IDEAS_1 $authorcontrols [aweight=hello], absorb(referee_id ms_number_id) vce(cluster ms_number_id)
	mat x = r(table)
	matrix b = b\(`b',x[1,1],x[5,1],x[6,1])
	mat drop x
	}
	clear
	svmat b
	drop if b1 == .
	rename b1 bw 
	rename b2 beta
	rename b3 lb
	rename b4 ub
	twoway (line lb bw, lpattern(dash) lcolor(black)) (line beta bw, lpattern(solid) lcolor(blue)) ///
	 (line ub bw, lpattern(dash) lcolor(black) legend(off)), xlabel(5(5)50)  ///
	 ytitle("Estimated coefficient with 95% CI") title("") scheme(s1mono) yline(0) ///
	 xtitle("Author-reviewer PhD both ranked between 1 and...") legend(label(1 "95% CI") label(2 "Est. Coefficient"))
	graph export "IDEASrankmatchthresholds.pdf", replace

	
	
	
	
	
